package com.pig4cloud.pigx.contract.api.v1.controller;


import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.customize.api.annotation.OpenApi;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.contract.api.v1.service.PositionHistoryServiceV1;
import com.pig4cloud.pigx.contract.api.v1.service.PositionServiceV1;
import com.pig4cloud.pigx.contract.dto.AppContractMarginChangeDTO;
import com.pig4cloud.pigx.contract.open.api.dto.OpenApiMultipleChangeDTOV1;
import com.pig4cloud.pigx.contract.open.api.vo.OpenApiPositionVOV1;
import com.pig4cloud.pigx.user.enums.UserApiKeyEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 开放API - 当前仓位 - v1版本
 *
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/contract/position" )
@Api(value = "api_position_v1", tags = "开放api-当前仓位")
public class PositionControllerV1 {

	private final PositionServiceV1 positionService;

	private final PositionHistoryServiceV1 positionHistoryService;

	/**
	 * 获取未平仓的持仓数量
	 * @param symbolName 币对名称
	 * @return long
	 */
	@ApiOperation(value = "获取未平仓的持仓数量", notes = "获取未平仓的持仓数量")
	@SysLog("获取未平仓的合约数量" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@GetMapping("/count")
	public R<BigDecimal> getCurrentCount(@RequestParam("symbolName") String symbolName) {
		return positionService.getCurrentCount(symbolName);
	}

	/**
	 * 获取当前仓位数量多空比
	 * @param symbolName 币对名称
	 * @return BigDecimal
	 */
	@ApiOperation(value = "获取当前仓位数量多空比", notes = "获取当前仓位数量多空比")
	@SysLog("获取当前仓位数量多空比" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@GetMapping("/proportion")
	public R<BigDecimal> getProportion(@RequestParam("symbolName") String symbolName) {
		return positionService.getProportion(symbolName);
	}

	/**
	 * 调整杠杆
	 * @param dto dto
	 * @return R
	 */
	@ApiOperation(value = "调整杠杆", notes = "调整杠杆")
	@SysLog("调整杠杆" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.CONTRACT,needSignature = true)
	@PostMapping("/multiple/change")
	public R multipleChange(@RequestBody OpenApiMultipleChangeDTOV1 dto) {
		return positionService.multipleChange(dto);
	}

	/**
	 * 逐仓调整保证金
	 * @param dto dto
	 * @return R
	 */
	@ApiOperation(value = "逐仓调整保证金", notes = "逐仓调整保证金")
	@SysLog("逐仓调整保证金")
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.CONTRACT,needSignature = true)
	@PostMapping("/margin/change")
	public R marginChange(@RequestBody AppContractMarginChangeDTO dto) {
		return positionService.marginChange(dto);
	}

	/**
	 * 获取当前持仓的仓位信息
	 * @param symbolName 币对名称
	 * @return R
	 */
	@ApiOperation(value = "获取当前持仓的仓位信息", notes = "获取当前持仓的仓位信息")
	@SysLog("获取当前持仓的仓位信息")
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@GetMapping("/current")
	public R<List<OpenApiPositionVOV1>> getCurrentPosition(@RequestParam("symbolName") String symbolName) {
		return positionService.getCurrentPosition(symbolName);
	}

}
